home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / ast_comp / yyref.shr / yyref / yyref-lex < prev    next >
Encoding:
Text File  |  1993-07-04  |  2.6 KB  |  202 lines

  1.  
  2.     /*******************************************************\
  3.     *                            *
  4.     *    X_ref for YACC - LEX file            *
  5.     *    ~~~~~~~~~~~~~~~~~~~~~~~~~            *
  6.     *    Date: Tue Jul  1 03:36:21 BST 1986        *
  7.     *                            *
  8.     \*******************************************************/
  9.  
  10. %{
  11.  
  12. #define        TRUE 1
  13. #define         FALSE 0
  14.  
  15. int    recognised;
  16. int     scope;
  17. char    c, lastchar, thischar;
  18.  
  19. %}
  20.  
  21.     /* abbreviations */
  22.  
  23. digit        [0-9]
  24. u_case        [A-Z]
  25. l_case        [a-z]
  26. id_char        [A-Za-z0-9_\.]
  27. letter        [A-Za-z\._]
  28. white        [\t ]
  29.  
  30.  
  31. %%
  32.  
  33. "/*"            {
  34.                 ECHO;
  35.                 recognised = FALSE;
  36.                 c = nextchar();
  37.                 while (recognised == FALSE)
  38.                 {
  39.                     while (c != '*')
  40.                         c = nextchar();
  41.                     c = nextchar();
  42.                     if (c == '\/')
  43.                         recognised = TRUE;
  44.                 }
  45.             }
  46. "%{"            {
  47.                 ECHO;
  48.                 recognised = FALSE;
  49.                 c = nextchar();
  50.                 while (recognised == FALSE)
  51.                 {
  52.                     while (c != '\%')
  53.                         c = nextchar();
  54.                     c = nextchar();
  55.                     if (c == '\}')
  56.                         recognised = TRUE;
  57.                 }
  58.                 return(PERCURL);
  59.             }
  60. "{"            {
  61.  
  62. /*
  63. *    Although LEX can cope with the full definition,
  64. *    ( "{"[^\}]*"}" ) this may overrun the lex buffer (200 chars).
  65. *    Thus this routine.
  66. */
  67.  
  68.   ECHO;
  69.   c = nextchar();
  70.   scope = 1;
  71.   while (scope > 0)
  72.     {
  73.       c = nextchar();
  74.       switch (c)
  75.     {
  76.     case '*':
  77.       if (lastchar == '/')
  78.         do
  79.           c = nextchar();
  80.       while ((lastchar != '*') || (c != '/'));
  81.       break;
  82.     case '"':
  83.       do
  84.         c = nextchar();
  85.       while ((lastchar == '\\') || (c != '"'));
  86.       break;
  87.     case '{': 
  88.       scope++; 
  89.       break;
  90.     case '}': 
  91.       scope--; 
  92.       break;
  93.     default:
  94.       break;
  95.     }
  96.     }
  97.   return(ACT);
  98. }
  99.  
  100.  
  101.  
  102. {letter}{id_char}*    {
  103.                 ECHO;
  104.                 return(IDENTIFIER);
  105.             }
  106. "'"(\\.|[^'])+"'"    {
  107.                 ECHO;
  108.                 return(CHARACTER);
  109.             }
  110. {white}+        {    
  111.                 ECHO;
  112.             }
  113. {digit}+        {
  114.                 ECHO;
  115.                 return(NUMBER);
  116.             }
  117. "%"{white}*"left"    {
  118.                 ECHO;
  119.                 return(LEFT);
  120.             }
  121. "%"{white}*"right"    {
  122.                 ECHO;
  123.                 return(RIGHT);
  124.             }
  125. "%"{white}*"nonassoc"    {
  126.                 ECHO;
  127.                 return(NONASSOC);
  128.             }
  129. "%"{white}*"token"    {
  130.                 ECHO;
  131.                 return(TOKEN);
  132.             }
  133. "%"{white}*"prec"    {
  134.                 ECHO;
  135.                 return(PREC);
  136.             }
  137. "%"{white}*"type"    {
  138.                 ECHO;
  139.                 return(TYPE);
  140.             }
  141. "%"{white}*"start"    {
  142.                 ECHO;
  143.                 return(START);
  144.             }
  145. "%"{white}*"union"    {
  146.                 ECHO;
  147.                 return(UNION);
  148.             }
  149. "%%"            {
  150.                 ECHO;
  151.                 return(PER);
  152.             }
  153. ":"            {
  154.                 ECHO;
  155.                 return(COLON);
  156.             }
  157. ";"            {
  158.                 ECHO;
  159.                 return(SEMICOLON);
  160.             }
  161. ","            {
  162.                 ECHO;
  163.                 return(COMMA);
  164.             }
  165. "|"            {
  166.                 ECHO;
  167.                 return(OR);
  168.             }
  169. "<"            {
  170.                 ECHO;
  171.                 return(LESS);
  172.             }
  173. ">"            {
  174.                 ECHO;
  175.                 return(GREATER);
  176.             }
  177. "\n"            {
  178.                 ECHO;
  179.                 nline(++line);
  180.             }
  181.  
  182. %%
  183.  
  184. yywrap()
  185. {
  186.     /* wrap-up procedure */
  187.     return(1);
  188. }
  189.  
  190. nextchar()
  191. {
  192.     char    c;
  193.     
  194.     c = input();
  195.     printf("%c",c);
  196.     if (c == '\n')
  197.         nline(++line);
  198.     lastchar = thischar;
  199.     thischar = c;
  200.     return(c);
  201. }
  202.